﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "pricing_New";
}
@section styles{
    <style>
        th {
            width: 150px;
            text-align: center;
        }

        #bigdiv {
            overflow: scroll;
            height:500px;
        }

        #HJ_CP_wl_table {
            width: 700px;
        }

            #HJ_CP_wl_table th {
                width: 14%;
            }

        .XJ_CPS_A1 {
            display: none;
            width: 660px;
            height: 500px;
            background-color: #E8ECF6;
            position: fixed;
            left: 300px;
            top: 100px;
            z-index: 1000;
            border: 1px solid black;
        }
    </style>
}
<fieldset class="boun">
    <legend></legend>
    <div class="row bian">
        <label class="col-sm-3 breadcrumb-item ">步骤五：采购核价</label>
        <ul id="lisul" class="row col-sm-5">
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu">5</li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>&rArr;
            <li class="lisu"></li>
        </ul>
    </div>
</fieldset>
<from>
    <fieldset>
        <label id="HJ_CP_sqd" style="display:none">@(Session["HJ_CP_appbian"])</label>
        <div class="Zhuyags">
            <div class="col-2 nav-item" id="divjibeng" style="background-color:#fff">@Resource.String48</div>
            <div class="col-2 nav-item" id="divbeizhu">@Resource.String49</div>
            <div class="col-2 nav-item" id="divtuzhi">@Resource.String50</div>
            <div class="col-2 nav-item" id="BOm_jn">物料信息</div>
            <div class="col-2 nav-item" id="divweituo" style="display:none">@Resource.String51</div>
        </div>
        <div>
            <div id="divsw1">
                <fieldset class="boun">
                    <legend class="len">@Resource.String428</legend>
                    <table id="BiaoTo" class="table-app">
                        @foreach (var item in ViewBag.PRO_kehu as List<Applications>)
                        {
                            <tr>
                                <td style="width:50%;">
                                    @Html.Label(Resource.String429): @item.App_Kehu
                                </td>
                                <td style="width:50%;">
                                    @Html.Label(Resource.String430):<label id="shenDan">@item.AP_bian </label>
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.Label(Resource.String431): @item.App_qishi</td>
                                <td>@Html.Label(Resource.String432):@item.App_JTime</td>
                            </tr>
                            <tr>
                                <td>@Html.Label(Resource.String433): @item.APP_name</td>
                                <td>@Html.Label(Resource.String434): @item.App_lei</td>
                            </tr>
                            <tr>
                                <td>@Html.Label(Resource.String435): @item.APP_Zhong</td>
                                <td style="width:50%;">@Html.Label(Resource.String436): <lable id="leb"></lable></td>
                            </tr>
                            <tr>
                                <td>@Html.Label(Resource.String437): @item.App_dizhi</td>
                                <td>@Html.Label(Resource.String438): @item.App_sho</td>
                            </tr>
                        }
                    </table>
                </fieldset>
            </div>
            <div id="divsw2" style="display:none">
                <div class="">
                    <div id="bigbox1">
                        <fieldset class="boun" id="boun" style="height:150px">
                            <legend class="len">@Resource.String558</legend>
                            <div id="RZ_gwzr" class="beizhugun">
                            </div>
                        </fieldset>
                    </div>
                    <div>
                        <fieldset class="boun" id="boun2">
                            <legend class="len">@Resource.String560</legend>
                            <div class="row">
                                <div class="col-2">@Resource.String563</div>
                                <div class="col-8"><textarea id="RZ_xznr" class="col-10" style="height:50px"></textarea></div>
                            </div>
                            <div style="text-align:right">
                                <button id="RZ_tjrz" class="col-2">@Resource.String564</button>
                            </div>
                        </fieldset>
                    </div>
                </div>
            </div>
            @*图纸备注*@
            <div id="divsw3" style="display:none">
                <div class="">
                    <fieldset class="boun" id="boun3">
                        <legend class="len">@Resource.String565</legend>
                        <table style="width:100%;text-align:center;height:100px" id="tab_wj">
                            <thead>
                                <tr style="background-color: #84acde">
                                    <td>@Resource.String566</td>
                                    <td>@Resource.String567</td>
                                    <td>@Resource.String568</td>
                                    <td>@Resource.String569</td>
                                    <td>上传</td>
                                    <td>删除</td>
                                </tr>
                            </thead>
                            <tbody id="logfuj">
                            </tbody>
                        </table>
                    </fieldset>
                </div>
            </div>
            @*bom查看*@
            <div id="divsw4" style="display:none">
                <div class="">
                    <fieldset class="boun">
                        <legend class="len">@Resource.String84</legend>
                        <table class="table tab">
                            <thead style="text-align:center;">
                                <tr style="background-color: #6e95bc">
                                    <th>物料名</th>
                                    <th>料号</th>
                                    <th>层级</th>
                                    <th>规格</th>
                                    <th>单位</th>
                                    <th>预计年用量</th>
                                    <th>BOM用量</th>
                                    <th>理论价格</th>
                                    <th>一级分类</th>
                                    <th>二级分类</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="div4__tb">
                            </tbody>
                        </table>
                    </fieldset>
                </div>
            </div>
        </div>

        <div style="margin-top:12px" class="row">
            <div class="col-lg-6" style="text-align:left">
                <button style="width:100px; text-align:center" id="HJ_CP_fh">@Resource.String509</button>
                <button style="width:100px; text-align:center" id="XJ_CP_WL_a1_b2"> @Resource.String508@Resource.String510</button>
            </div>
            <div class="col-lg-6" style="text-align:right">
                @*<button id="HJ_CP_jgsx">@Resource.String523</button>
                    <button id="HJ_CP_jgjx">@Resource.String524</button>*@
                @*<button id="HJ_CP_yjxz">@Resource.String525</button>*@
                <button id="HJ_CP_yjtj">@Resource.String526</button>
            </div>

        </div>
        <div class="row" style="">
            <div id="bigdiv" class="col-4" style="overflow-x:scroll;">
                <table id="HJ_CP_wl_table" class="tab table" style="width:200%">
                    <thead  class="thead-light">
                        <tr>
                            <th style="width:30px;"><input type="checkbox" id="quanbuaxians" /></th>
                            <th style="display:none">@Resource.String511</th>
                            <th>@Resource.String512</th>
                            <th>@Resource.String513</th>
                            <th>@Resource.String514</th>
                            <th>@Resource.String515</th>
                            <th>@Resource.String516</th>
                            <th>@Resource.String517</th>
                            <th>@Resource.String518</th>
                        </tr>
                    </thead>
                    <tbody data-spy="scroll" id="HJ_CP_tb" style="height:500px;overflow-x:hidden">
                    </tbody>
                </table>
            </div>
            <div class="col-8" style=" overflow: scroll; height: 500px; max-height: 500px">
                <table id="HJ_CP_gys_ta">
                </table>
            </div>
        </div>
    </fieldset>
    <div style="display:none" class="shenpijng XJ_CPS_A1">
        <table>
            <thead>
                <tr>
                    <th>@Resource.String527</th>
                    <th></th>
                    <th>
                    </th>
                    <th>
                        <select id="SELsw">
                            <option value="1">@Resource.String528</option>
                            <option value="2">@Resource.String529</option>
                            <option value="3">@Resource.String530</option>
                        </select>
                    </th>
                </tr>
                <tr>
                    <td>@Resource.String531</td>
                    <td>@Resource.String532</td>
                    <td>@Resource.String533</td>
                    <td>@Resource.String534</td>
                </tr>
            </thead>
            <tbody id="ajinfs">
                <tr>
                    <td>
                        <input type="text" value="" class="form-control" id="shenpin" list="seleect_code" placeholder="@Resource.String535" />
                        <datalist id="seleect_code" class="form-control" style="display:none">
                        </datalist>
                    </td>
                    <td><input type="text" readonly class="form-control" /></td>
                    <td><input type="date" class="form-control" id="dateC" /></td>
                </tr>
                <tr style="display:none">
                    <td>
                        <input type="text" value="" class="form-control" id="shenpin1" list="seleect_code" placeholder="@Resource.String536" />
                        <datalist id="seleect_code" class="form-control" style="display:none">
                        </datalist>
                    </td>
                    <td><input type="text" readonly class="form-control" /></td>
                    <td><input type="date" class="form-control" id="dateC1" /></td>
                </tr>
                <tr style="display:none">
                    <td>
                        <input type="text" value="" class="form-control" id="shenpin2" list="seleect_code" placeholder="@Resource.String537" />
                        <datalist id="seleect_code" class="form-control" style="display:none">
                        </datalist>
                    </td>
                    <td><input type="text" readonly class="form-control" /></td>
                    <td><input type="date" class="form-control" id="dateC2" /></td>
                </tr>
                <tr><td style="color:red">@Resource.String538</td></tr>
            </tbody>
        </table>
        <input type="button" id="buton" value="@Resource.String539" />
        <input type="button" id="butonwes" value="@Resource.String540" />
    </div>
    <div id="show_shangc" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:400px;width:600px">
        <div style="text-align: right; background-color: #84acde;"><span class="QUED_quxiao" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div class="row">
            <div class="col-lg-2" id="clfl">材料/辅料</div>
            <div class="col-lg-2" id="gyqt">工艺/其他</div>
        </div>
        <div style="margin: 20px 10px; padding: 10px; background-color: #fff; ">
            <div style="display:block" id="clfl_2">
                <table class="table tab">
                    <thead class="thead-light">
                        <tr style="text-align-last:center;">
                            <td>材料名</td>
                            <td>规格</td>
                            <td>使用数量</td>
                            <td>价格</td>
                        </tr>
                    </thead>
                    <tbody id="wlxi">
                    </tbody>
                </table>
            </div>
            <div style="display:none" id="gyqt_2">
                <table class="table tab">
                    <thead class="thead-light">
                        <tr style="text-align-last:center;">
                            <td>工艺名</td>
                            <td>规格</td>
                            <td>价格</td>
                            <td>备注</td>
                        </tr>
                    </thead>
                    <tbody id="gyqted">
                    </tbody>
                </table>
            </div>
        </div>
        <div style="text-align:center"><button class="QUED_quxiao">@Resource.String126</button></div>
    </div>
</from>
@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li6").css({ "color": "black", "background-color": "white" })
            var HJ_CP_sqd = $("#HJ_CP_sqd").text()
            ajax_BOM()
            Supplier_selection()
            Add_HJ_CP()
            Exit_GYSHJ_ZT()
            Back_Over()
            Completed_price_check()
            find_fbom()
            function find_fbom() {
                $.ajax({
                    url: '/Procure/Pricing_New',
                    type: 'GET',
                    data: { "APP_bian": HJ_CP_sqd, "state": 8 },
                    success: function (data) {
                        createTR2(data);
                    },
                    error: function () {
                        alert('Request Error')
                    }
                })
            }

            function createTR2(e) {
                $("#div4__tb tr").remove()
                $.each(e, function (i, item) {
                    var $tr =
                        $(`
                            <tr>
                                <td style="display:none" class="">${item.BOM2_id}</td>
                                <td>${item.BOM2_wuLiu}</td>
                                <td>${item.BOM2_liao}</td>
                                <td>${item.BOM2_chen}</td>
                                <td>${item.BOM2_Guige}</td>
                                <td>${item.BOM2_fenzi}</td>
                                <td>${item.BOM2_Nian}</td>
                                <td>${item.BOM2_Yong}</td>
                                <td>${item.BOM2_mioa}</td>
                                <td>${item.BOM2_Sone}</td>
                                <td>${item.BOM2_ST}</td>
                                <td><a id="ckwlgy" href="#">查看物料工艺</a></td>
                            </tr>
                        `);
                    $('#div4__tb').append($tr);
                })
            }

            $(document).on("click", "#clfl", function () {
                $("#clfl_2").css({ display: "block" })
                $("#gyqt_2").css({ display: "none" })
            })
            $(document).on("click", "#gyqt", function () {
                $("#clfl_2").css({ display: "none" })
                $("#gyqt_2").css({ display: "block" })
            })
            $(document).on("click", "#ckwlgy", function (e) {
                var name = $(e.target).parent().parent().children().eq(0).text()
                var bain = $("#shenDan").text()
                console.log(name, bain)
                window.location.href = "/Material/Index?names=" + bain + "&bid=" + name + "&fro=HJJM";
                $.ajax({
                    url: '/ShenPI/HJSP',
                    type: 'POST',
                    data: { "state": 6, "Bians": name },
                    success: function (data) {
                        if (data == "该行不存在") {
                        } else {

                        }
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            })
            $(document).on("click", ".QUED_quxiao", function () {
                $("#show_shangc").css({ "display": "none" })
            })

            $(document).on("click", "#quanbuaxians", function (e) {
                if ($(e.taget).prop("checked")) {
                    $(".suanzgongn").prop("checked", true)
                }
                else {
                    $(".suanzgongn").prop("checked", false)
                }
            })

            //查找BOM中所有种类的物料
            $(document).on("click", ".suanzgongn", function () {
                $('#HJ_CP_gyshj tr').remove();
                $("#HJ_CP_gys_ta table").remove()
                var WLTC = "";
                $("input[class=suanzgongn]:checked").each(function (i, item) {
                    var id = $(item).parent().next().text()
                    $.ajax({
                        url: '/Procure/Pricing_New',
                        type: 'GET',
                        data: { "HJ_CP_cktj": id, "state": 6 },
                        success: function (data) {
                            if (data == "F") {
                                var WLSED = $(item).parent().next().next().next().text()
                                WLTC += WLSED;
                            } else {
                                var $table = $(`${data}`)
                                $("#HJ_CP_gys_ta").append($table)
                                //判断最小值
                                $("#HSJI_KO tr").each(function () {
                                    var shund = Number.MAX_SAFE_INTEGER;//最小值
                                    $(this).children().find('span').each(function () {
                                        var ZHI = $(this).parent().children().eq(0).text() * 1
                                        if (!isNaN(ZHI) && ZHI < shund) { // 如果value是一个数字且小于当前的最小值
                                            shund = ZHI; //更新最小值
                                            $(this).prev().prop('checked', true);
                                        }
                                    })
                                    $(this).find('input[type="radio"]:checked').each(function () {
                                        $(this).prev().css({ "color": "#0077ff" })
                                    })
                                })
                            }
                        },
                        error: function () {
                            alert('Request Error')
                        }
                    })
                })
                if (WLTC != "") {
                    alert(WLTC+"无询价记录！")
                }
            })
            function ajax_BOM() {
                $.ajax({
                    url: '/Procure/Pricing_New',
                    type: 'GET',
                    data: { "APP_bian": HJ_CP_sqd, "state": 1 },
                    success: function (data) {
                        createTR(data);
                    },
                    error: function () {
                        alert('Request Error')
                    }
                })
            }
            //打印物料信息
            function createTR(data) {
                console.log(data)
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var qishi_time = year + "/" + month + "/" + date
                $('#HJ_CP_tb tr').remove();
                $('#HJ_CP_gys_ta thead').remove();
                $('#HJ_CP_gys_ta tbody').remove();
                if ($("#Login_sf").text() == "业务发展部经理" || $("#Login_sf").text() == "采购主管") {
                    $.each(data, function (i, item) {
                        var $tr =
                            $(`
                                      <tr>
                                        <th style="width:30px;"><input type="checkbox" class="suanzgongn" /></th>
                                        <th style="display:none" class="gyspa">${item.BOM2_id}</th>
                                        <th id="HJ_CP_WL_z1">${item.BOM2_wuLiu}</th>
                                        <th id="HJ_CP_WlLh_z1">${item.BOM2_liao}</th>
                                        <th id="HJ_CP_GYS_z1">${item.Inf_gong}</th>
                                        <th id="HJ_CP_HJ_z1">${item.Inf_huiP}</th>
                                        <th class="HJ_CP_LLJG_z1" id="${item.BOM2_liao}lljg">${item.BOM2_mioa}</th>
                                        <th class="HJ_CP_FQRQ" id="HJ_CP_FQ_z1">${qishi_time}</th>
                                        <th><input type="date" class="HJ_CP_SXRQ" id="HJ_CP_SX_z1" style="width:135px"/></th>
                                    </tr>
                            `);
                             $('#HJ_CP_tb').append($tr);
                        @*if (item.Inf_gong == "") {
                            var $tr =
                                $(`
                                    <thead>
                                        <tr>
                                            <th colspan="5" class="HJ_CP_WLM" id="${item.BOM2_wuLiu}bt" style="font-size:150%">${item.BOM2_wuLiu}</th>
                                        </tr>
                                        <tr>
                                            <th>最优选择</th>
                                            <th>@Resource.String542</th>
                                            <th>@Resource.String543</th>
                                            <th>@Resource.String544</th>
                                            <th>@Resource.String545</th>
                                            <th id="janwh" style="display:none">选择非最低价，需要提交备注</th>
                                        </tr>
                                    </thead >
                                    <tbody id="HJ_CP_gyshj">

                                    </tbody>
                               `);
                            $('#HJ_CP_gys_ta').append($tr);
                        }*@
                    })
                }
                else if ($("#Login_sf").text() == "采购员") {
                    $.ajax({
                        url: '/Procure/Detailed',
                        type: 'GET',
                        data: { "id": $("#Login_name").text(), "state": 1 },
                        success: function (date) {
                            $.each(date, function (i, obj) {
                                $.each(data, function (i, item) {
                                    console.log(obj, item.BOM2_ST)
                                    if (obj.du_name == item.BOM2_ST) {
                                        console.log(1)
                                        var $tr =
                                            $(`
                                                  <tr>
                                                      <tr>
                                                        <th style="width:30px;"><input type="checkbox" class="suanzgongn"/></th>
                                                        <th style="display:none" class="gyspa">${item.BOM2_id}</th>
                                                        <th id="HJ_CP_WL_z1">${item.BOM2_wuLiu}</th>
                                                        <th id="HJ_CP_WlLh_z1">${item.BOM2_liao}</th>
                                                        <th id="HJ_CP_GYS_z1">${item.Inf_gong}</th>
                                                        <th id="HJ_CP_HJ_z1">${item.Inf_huiP}</th>
                                                        <th class="HJ_CP_LLJG_z1" id="${item.BOM2_liao}lljg">${item.BOM2_mioa}</th>
                                                        <th class="HJ_CP_FQRQ" id="HJ_CP_FQ_z1">${qishi_time}</th>
                                                        <th><input type="date" class="HJ_CP_SXRQ" id="HJ_CP_SX_z1" style="width:135px"/></th>
                                                    </tr>
                                                  </tr>
                                            `);
                                                        $('#HJ_CP_tb').append($tr);
                                        @*if (item.Inf_gong == "") {
                                            var $tr =
                                                $(`
                                                    <thead>
                                                        <tr>
                                                            <th colspan="5" class="HJ_CP_WLM" id="${item.BOM2_wuLiu}bt" style="font-size:150%">${item.BOM2_wuLiu}</th>
                                                        </tr>
                                                        <tr>
                                                            <th>最优选择</th>
                                                            <th>@Resource.String542</th>
                                                            <th>@Resource.String543</th>
                                                            <th>@Resource.String544</th>
                                                            <th>@Resource.String545</th>
                                                            <th id="janwh" style="display:none">选择非最低价，需要提交备注</th>
                                                        </tr>
                                                    </thead >
                                                    <tbody id="HJ_CP_gyshj">

                                                    </tbody>
                                               `);
                                            $('#HJ_CP_gys_ta').append($tr);
                                        }*@
                                    }
                                })
                            })
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }


            }

            //打印申请单下所有询价信息
            function createHJ_TR(data) {
                var index = 0
                var items=""
                $("#HJ_CP_gyshj tr").remove()

                //$.ajax({
                //    url: '/Procure/Pricing_New',
                //    type: 'GET',
                //    data: { "HJ_CP_cktj": item.Fo_id, "state": 7 },
                //    success: function (data) {

                //    },
                //    error: function () {
                //        alert('Request Error')
                //    }
                //})
            }

            //选择审批人数
            $(document).on("change", "#SELsw", function () {
                $(document).on("change", "#SELsw", function () {
                    var AS1 = $(this).val()
                    if (AS1 == "1") {
                        $("#shenpin").parent().parent().show()
                        $("#shenpin1,#shenpin2").parent().parent().hide()
                        $("#shenpin1,#shenpin2").text()
                    }
                    if (AS1 == "2") {
                        $("#shenpin,#shenpin1").parent().parent().show()
                        $("#shenpin2").parent().parent().hide()
                        $("#shenpin2").text()
                    }
                    if (AS1 == "3") {
                        $("#shenpin,#shenpin1,#shenpin2").parent().parent().show()

                    }
                    sjiQxnf()
                })
            })
            sjiQxnf()
            function sjiQxnf() {
                var now = new Date($.now());
                //获取当前年月日
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var Qs = year + "/" + month + "/" + date
                //$("#shenpin").parent().next().children().val(qishi_time2)
                $("#ajinfs tr td:nth-child(2)").each(function (w, PLk) {
                    $(PLk).children().val(Qs)
                })
            }
            //保存审批

            //点击调用方法查找所有询价信息
            $(document).on("click", "#HJ_CP_cksy", function () {
                ajax_INF()
            })
            //下拉框改变查找的询价信息
            $(document).on("change", "#HJ_CP_cktj", function () {
                var HJ_CP_cktj = $("#HJ_CP_cktj").val()
                if (HJ_CP_cktj != 0 && HJ_CP_cktj != 2) {
                    $.ajax({
                        url: '/Procure/Pricing_New',
                        type: 'GET',
                        data: { "HJ_CP_cktj": HJ_CP_cktj, "APP_bian": HJ_CP_sqd, "state": 3 },
                        success: function (data) {
                            createHJ_TR(data);
                        },
                        error: function () {
                            alert('Request Error')
                        }
                    })
                }
                else if (HJ_CP_cktj == 2) {
                    createHJ_TR(data, 2)
                }
            })
            //升序排列
            $(document).on("click", "#HJ_CP_jgsx", function () {
                $.ajax({
                    url: '/Procure/Pricing_New',
                    type: 'GET',
                    data: { "APP_bian": HJ_CP_sqd, "state": 4 },
                    success: function (data) {
                        createHJ_TR(data);
                    },
                    error: function () {
                        alert('Request Error')
                    }
                })
            })
            //降序排列
            $(document).on("click", "#HJ_CP_jgjx", function () {
                $.ajax({
                    url: '/Procure/Pricing_New',
                    type: 'GET',
                    data: { "APP_bian": HJ_CP_sqd, "state": 5 },
                    success: function (data) {
                        createHJ_TR(data);
                    },
                    error: function () {
                        alert('Request Error')
                    }
                })
            })
            //将选择的物料回价入库
            function Add_HJ_CP() {
                $(document).on("click", "#HJ_CP_RK", function () {
                    var BZJG = []
                    var BZJG_CD = $(':checkbox:checked').parent().parent().length;
                    if (BZJG_CD < 0) {
                        alert("请选择一个供应商回价")
                    }
                    else {
                        $('input[type=radio]:checked').parent().parent().each(function (i, item) {

                            BZJG.push({
                                Nd_Gong: $("th[id='HJ_CP_GYS_z1']", item).text(),
                                Nd_wuLiao: $("th[id='HJ_CP_WL_z1']", item).text(),
                                Fo_id: $("th[id='HJ_CP_WlLh_z1']", item).text(),
                                Nd_jiage: $("th[id='HJ_CP_HJ_z1']", item).text(),
                                Nd_shengxiao: $("th[id='HJ_CP_FQ_z1']", item).text(),
                                Nd_shixiao: $("th[id='HJ_CP_SX_z1']", item).val()
                            })

                        })
                        $.ajax({
                            url: "/Procure/AddNdardo_CP",
                            type: 'POST',
                            data: JSON.stringify(BZJG),
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            success: function (text) {
                                alert(text)
                            },
                            error: function (text) {
                                alert("系统错误" + text);
                            }
                        })
                    }
                })
            }
            //供应商回价全选
            function Supplier_selection() {

                $(document).on("click", "#HJ_CP_yjxz", function () {
                    $("#HJ_CP_gys_ta input[type=checkbox]").attr("checked", true)
                    $(".HJ_CP_qxgys").attr("checked", false)
                })
                //$(document).on("click", ".HJ_CP_qxgys", function (e) {
                //    var checkbox = $(e.target).parent().parent().parent().next().children().get()
                //    if ($(e.target).attr("checked", true)) {
                //        console.log(checkbox)
                //        $.each(checkbox, function (i,item) {

                //        })
                //    }
                //})
            }
            //最优推荐
            $(document).on("click", "input[type='radio']", function () {
                var sjin = 0;
                $(this).parent().parent().parent().find("tr").each(function () {
                    var shund = Number.MAX_SAFE_INTEGER;//最大值
                    if ($(this).children().find("span").length == 0) {

                    } else {
                        $(this).children().find("span").each(function () {
                            var ZHI = $(this).parent().children().eq(0).text()
                            if (!isNaN(ZHI) && ZHI < shund) { // 如果value是一个数字且小于当前的最小值
                                shund = ZHI; // 更新最小值
                            }
                        })
                        var shhnf = $(this).children().find("input[type='radio']:checked").parent().children().eq(0).text();
                        if (shhnf > shund) {
                            sjin++;
                        }
                    }
                })
                if (sjin > 0) {
                    var $inp = $(`<input type="text" class="HJ_B" style="display:none" placeholder="添加推荐理由！"/>`)
                    if ($(this).parent().parent().parent().children().eq(0).children().find('input[type="text"]').length < 1) {
                        $(this).parent().parent().parent().children().eq(0).children().append($inp)
                    }
                } else {
                    $(this).parent().parent().parent().children().eq(0).children().find('input[type="text"]').remove()
                }
            })

            //修改选择的供应商回价的状态
            function Exit_GYSHJ_ZT() {
                $(document).on("click", "#HJ_CP_yjtj", function () {
                    var BZJG = []
                    var BOM_bei = []
                    var BZJG_CD = $('#HJ_CP_gys_ta :checkbox:checked').parent().parent().length;
                    if (BZJG_CD < 0) {
                        alert("请选择一个供应商回价")
                    }
                    else {
                        var index = 0
                        var Bomjins = 0;
                        $(".HJ_BZ_i_x1").each(function (i, item) {
                            if ($(item).val() == "") {
                                index++
                            }
                        })
                        //有替换供应商
                        $(".HJ_B").each(function (i, item) {
                            if ($(item).val() == "") {
                                Bomjins++
                            }
                        })
                        if (index == 0) {
                            var shhlj = 0;
                            $('input[type=radio]:checked').parent().parent().each(function (i, item) {
                                console.log(item)
                                BZJG.push({
                                    Inf_id: $("input[type=radio]:checked", item).parent().children().last().text(),
                                    Inf_zhuang: "已确认",
                                })
                                //利润
                                var sxfn = $("input[type=radio]:checked", item).parent().children().eq(-2).text();//百分比
                                var bzcbn = $("input[type=radio]:checked", item).parent().parent().children().eq(1).text();//标准成本
                                var JMKN = sxfn.split('：')[1]
                                if ((JMKN.split('%')[0]*1) > 10 && bzcbn != "0") {
                                    shhlj++
                                }
                                if (shhlj > 0) {
                                    var WULIAO = $(this).parent().children().eq(0).text()
                                    var LIyo = prompt("添加"+WULIAO+"高于理论价格10%理由：");
                                    if (LIyo != null) {
                                        BOM_bei.push({
                                            Inf_id: $("input[type=radio]:checked", item).parent().children().last().text(),// Inf_id
                                            Inf_zhuang: LIyo,
                                            Inf_gong: 2  //2:低于理论价格10%理由
                                        })
                                    } else {
                                        return 
                                    }
                                }
                            })
                            if (Bomjins > 0) {
                                var LIyo = prompt("请输入推荐理由：");
                                if (LIyo != null) {
                                    $('input[type=radio]:checked').parent().parent().each(function (i, item) {
                                        BOM_bei.push({
                                            Inf_id: $("input[type=radio]:checked", item).parent().children().last().text(),
                                            Inf_zhuang: LIyo,
                                            Inf_gong: 1 ////2:供应商推荐
                                        })
                                        console.log("共" + BOM_bei.length + "数据");
                                        console.log(BOM_bei);
                                    })
                                } else {
                                    return
                                }
                            }
                            //if (shhlj>0) {
                            //    var LIyo = prompt("高于理论价格10%理由：");
                            //    if (LIyo != null) {
                            //        $('input[type=radio]:checked').parent().parent().each(function (i, item) {
                            //            BOM_bei.push({
                            //                Inf_id: $("input[type=radio]:checked", item).parent().children().last().text(),// Inf_id
                            //                Inf_zhuang: LIyo,
                            //                Inf_gong: 2  //2:低于理论价格10%理由
                            //            })
                            //            console.log("共" + BOM_bei.length + "数据");
                            //            console.log(BOM_bei);
                            //        })
                            //    } else {
                            //        return
                            //    }
                            //}
                            $.ajax({
                                url: "/Procure/Modify_INF_zhuang",
                                type: 'POST',
                                data: JSON.stringify(BZJG),
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                success: function (text) {
                                    alert(text);
                                    if (BOM_bei.length != 0) {
                                        $.ajax({
                                            url: "/Procure/Modify_Nng",
                                            type: 'POST',
                                            data: JSON.stringify(BOM_bei),
                                            contentType: "application/json;charset=utf-8",
                                            dataType: "json",
                                            success: function (text) {
                                                if (text == 0) {
                                                    alert("备注添加失败！")
                                                }
                                            },
                                            error: function (text) {
                                                alert(text);
                                            }
                                        })
                                    }
                                    ajax_BOM()
                                },
                                error: function (text) {
                                    alert(text);
                                }
                            })
                        } 
                    }
                })
            }
            //添加生效时间和过期时间
            function time() {
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var qishi_time = year + "/" + month + "/" + date
                var shixiao_time
                if (month == 12) {
                    shixiao_time = year + "/" + 1 + "/" + date
                }
                else {
                    shixiao_time = year + "/" + month + 1 + "/" + date
                }
            }
            //转跳到报表页面
            function Back_Over() {
                $(document).on("click", "#HJ_CP_fh", function () {
                    window.location.href = "/Procure/Price_main"
                })
            }
            //修改步骤完成核价
            function Completed_price_check() {
                $(document).on("click", "#HJ_CP_wc", function () {
                    $.ajax({
                        url: '/Procure/Index',
                        type: 'POST',
                        data: { "CG_INFSQD": HJ_CP_sqd, "App_bu": 6 },
                        success: function (data) {
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                    window.location.href = "/Home/Quotation_to_be_generated"
                })
            }

            $(document).on("click", "#XJ_CP_WL_a1_b2", function () {
                var Bomini = [];
                $(".gyspa").each(function (i, item) {
                    Bomini.push({
                        BOM2_id: $(item).text(),
                        BOM2_bian: $("#shenDan").text(),
                        BOM2_Guige: $(item).next().next().next().text()
                    })
                })
                console.log(Bomini);
                var INji = 0;
                Bomini.forEach(function (i, PS) {
                    if (i.BOM2_Guige=='') {
                        INji++;
                    }
                })
                if (INji == 0) {
                    $.ajax({
                        url: '/Procure/Modify_BOM_PD_hj',
                        type: 'POST',
                        data: JSON.stringify(Bomini),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            alert(data)
                            if (data == "核价全部完成，请等待审核") {
                                var now = new Date($.now());
                                //获取当前年月日
                                var year = (now.getFullYear()).toString();
                                var month = (now.getMonth() + 1).toString();
                                var date = (now.getDate()).toString();
                                var Qs = year + "/" + month + "/" + date
                                //填充申请人信息
                                var sjinfPLM = ""
                                var FJIDNS = {
                                    "FFirst": "采购主管",//一级审批人
                                    "FFZ": "审批中",//状态
                                    "FFS": $("#dateC").val(),
                                    "FTwo": "业务发展部经理",//二级审批人
                                    "FTZ": "审批中",//状态
                                    "FFIZ": $("#dateC2").val(),
                                    "FBzt": $("input[name='jisnfdd']").val(),//备注
                                    "FJINF": $("#HJ_CP_sqd").text(),
                                    "FShenR": $("#Login_N").text(),
                                    "FSHENP": "2",
                                    "FMIao": "核价审批",
                                    "FQsj": Qs,
                                    "Fzhuang": "审核中"
                                }
                                if (FJIDNS.FFirst != "" || FJIDNS.FTwo != "" || FJIDNS.FThree != "") {
                                    $.ajax({
                                        url: "/Procure/HeaApplication",
                                        type: 'POST',
                                        data: FJIDNS,
                                        success: function (text) {
                                            alert(text)
                                            window.location.href = "/Procure/Price_main"
                                        },
                                        error: function (text) {
                                            alert("系统错误" + text);
                                        }
                                    })
                                } else {
                                    alert("shijnfoodod")

                                }
                            } else {
                                window.location.href = "/Procure/Price_main"
                            }
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                }
                else {
                    alert("请先提交对应的供应商！")
                }
               /* $.ajax({
                    url: "/Procure/Modify_INF_zhuang61",
                    type: 'POST',
                    data: { "names": $("#shenDan").text() },
                    success: function (text) {
                        if (text == "N") {
                            alert("等待其他物流核价")
                        }
                    },
                    error: function (text) {
                        alert("系统错误" + text);
                    }
                })*/
            })
        })
        $(function () {
            gettbz()//搜索备注信息
            //点击切换基础信息，备注信息，图纸沟通
            $(function () {
                $("#divjibeng").click(function (e) {
                    $("#divsw1").css({ "display": "block" });
                    $("#divsw2").css({ "display": "none" });
                    $("#divsw3").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divbeizhu").click(function (e) {
                    $("#divsw2").css({ "display": "block" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw3").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divtuzhi").click(function (e) {
                    $("#divsw3").css({ "display": "block" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw2").css({ "display": "none" });
                    $("#divsw4").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#BOm_jn").click(function (e) {
                    $("#divsw4").css({ "display": "block" });
                    $("#divsw3").css({ "display": "none" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw2").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
            })
            //获取备注信息
            function gettbz() {
                var kan = $("#shenDan").text();
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": kan, "state": 4 },
                    success: function (sjik) {
                        console.log(sjik)
                        $("#RZ_gwzr div").remove();
                        $.each(sjik, function (i, item) {
                            var $tr = $(`<div>
                                    <div>
                                        <span style="color:red">${item.B_BR}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>${item.B_Date}</span>
                                    </div>
                                    <div style="border-bottom:1px solid #808080">
                                        ${item.B_bei}
                                    </div>
                                </div>`);
                            $("#RZ_gwzr").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
             Load_design_table()
            //获取图纸信息
            function Load_design_table() {
                $.ajax({
                    url: '/Application/Application',
                    type: 'POST',
                    data: { "state": 3, "App_ban": $('#shenDan').text()},
                    success: function (path) {
                        createFJ(path)
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
            function createFJ(fgggh) {
                $("#logfuj tr").remove();
                $("#div3__tb tr").remove();
                var ind1 = 1
                var ind2 = 1
                var temp=0
                $.each(fgggh, function (i, item) {
                    var x = item.De_dizhi
                    if (item.DE_lei == "图纸") {
                        var $tr = (`
                        <tr class="log_tr">
                            <td style="display:none">${item.DE_id}</td>
                            <td>${ind1}</td>
                            <td>${item.DE_TZname}</td>
                            <td>${item.bom_id}</td>
                            <td>${item.De_shijian}</td>
                            <td>${item.De_ren}</td>
                            <td>
                                <input type="number" readonly="readonly" value="${item.DE_Slong}" style="width:60px;height:30px"/>
                            </td>
                            <td><a href="#" id="log_SC">删除</a>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">@Resource.String582</a></td>
                        </tr>`);
                        $("#div3__tb").append($tr);
                        ind1++
                        temp += item.DE_Slong*1
                    }
                    else {
                        var $tr = (`
                        <tr class="log_tr">
                            <td style="display:none">${item.DE_id}</td>
                            <td>${ind2}</td>
                            <td>${item.De_dizhi}</td>
                            <td>${item.De_shijian}</td>
                            <td>${item.De_ren}</td>
                            <td><a href="/Contracts/Download_file?path=${x}" id="log_SZ">@Resource.String582</a></td>
                        </tr>`);
                        $("#logfuj").append($tr);
                        ind2++
                    }
                })
                $("#SJ_ZYS").text(temp)
            }
            //日志写入数据库
            $(document).on("click", "#RZ_tjrz", function () {
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var hours = (now.getHours()).toString()
                var minutes = (now.getMinutes()).toString()

                //组合当前日期
                var sqrq = year + "/" + month + "/" + date + " " + hours + ":" + minutes
                var rzxx = {
                    B_Bian: $("#shenDan").text(),
                    B_BR: $('#Login_N').text(),
                    B_Date: sqrq,
                    B_bei: $('#RZ_xznr').val(),

                };
                console.log(rzxx)
                $.ajax({
                    url: "/Contracts/AddLogs",
                    type: "POST",
                    data: rzxx,
                    success: function (data) {
                        alert(data)
                        $('#RZ_xznr').val("")
                        gettbz()
                    },
                    error: function (data) {
                        alert("erroer");
                    },
                })
            })

        })

    </script>
}